/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main;

import java.io.File;
import lejos.nxt.Sound;
import modes.Mode;

import modes.ModeController;

import navigation.IllegalMoveException;
import navigation.Navigator;

/**
 * Start of the program
 * @author Max
 */
public class ChewieMobil
{

    private Mode mode;
    private ColorSensorChew color;
    private Navigator navi;
    private SonicSensor sonic;
    private Engine engine;
    private SensorEngine rotation;
    private ModeController modeController;
    Thread magic;

    /**
     * Creates the search navigator
     * Sets the speed of the engines
     * 
     * @throws IllegalMoveException
     */
    public ChewieMobil() throws IllegalMoveException
    {
        color = new ColorSensorChew();
        navi = config.Config.getSearchRedPointNavigator();
        sonic = new SonicSensor();
        engine = new Engine(350);
        rotation = new SensorEngine(900);

        mode = Mode.BLACK;
        modeController = new ModeController(engine, rotation, color, sonic, navi);
        magic = new Thread(new MagicButton(engine, rotation));
        magic.start();
    }

    public static void main(String[] args) throws InterruptedException, IllegalMoveException
    {

        ChewieMobil chmb = new ChewieMobil();

        chmb.run();

    }

    /**
     * Runs until exit has been reached
     * Chewie celebrates his epic success
     * @throws InterruptedException
     */
    public void run() throws InterruptedException
    {

        while (mode != Mode.END)
        {
            mode = modeController.changeMode(mode);

        }
        magic.interrupt();
        Sound.playSample(new File("chewy1.wav"), 100);
        engine.setSpeed(900);
        engine.rotateLeft();
        for (int i = 0; i < 2000; ++i)
        {
            if (i % 500 == 0)
            {
                Sound.playSample(new File("chewy1.wav"), 100);
            }
            Thread.sleep(1);
        }
        engine.stop();

    }
}

   

   
   

    

   

  

   

 

   

   

   

    

   

    
    
   
    


   
   
   
   
 

